from django import forms

from . import models
from main import widgets



class AddingBookForm(forms.ModelForm):

    LIST_OF_AUTHORS_CHOICES = models.Author.objects.values_list('slug', 'name').all()
    LIST_OF_GROUPS_CHOICES = models.Group.objects.values_list('slug', 'title').all()

    author = forms.MultipleChoiceField(label='Автор', choices=LIST_OF_AUTHORS_CHOICES, widget=forms.SelectMultiple(
        attrs={'class': 'selection-from-list'}))

    group = forms.MultipleChoiceField(label='Группа', choices=LIST_OF_GROUPS_CHOICES, widget=forms.SelectMultiple(
        attrs={'class': 'selection-from-list'}))

    image = forms.FileField(label='Обложка книги', widget=widgets.UploadFile(attrs={
        'data-add-new-book-cover': "true"}))
    file = forms.FileField(label='Книга', widget=widgets.UploadFile(attrs={
        'data-add-book': 'true'}))
    background = forms.FileField(label='Фоновое изображение', widget=widgets.UploadFile(attrs={
        'data-add-background-image': 'true'}))

    class Meta:
        fields = ('title', 'description', 'image', 'file', 'background', 'author', 'group')
        model = models.Book
